import React, { useState } from 'react';
import { Spin } from 'antd';

const useSpinning = ({title}: {title: string}) => {
  const [spinning, setSpinning] = useState<boolean>(false);
  const show = (sec = 0) => {
    setSpinning(true);
    if (sec > 0) {
      setTimeout(() => {
        setSpinning(false);
      }, sec);
    }
  };
  const hide = () => setSpinning(false);

  const SpinDom = () => {
    return (<Spin spinning={spinning} tip={title} fullscreen />)
  }
  return { SpinDom, show, hide };
}

export default useSpinning;